/**
 * Created by sky on 2019/3/8.
 */
layui.define(['mobile'], function (exports) {
    var mobile = layui.mobile
        , layim = mobile.layim
        , layer = mobile.layer;

    var isAgency = window.location.search.includes('role=agent');


    function getParam(paramName) {
        var paramValue = "", isFound = !1;
        if (window.location.search.indexOf("?") == 0 && window.location.search.indexOf("=") > 1) {
            var arrSource = unescape(window.location.search).substring(1, window.location.search.length).split("&"), i = 0;
            while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
        }
        return paramValue == "" && (paramValue = null), paramValue
    };


    layim.config({
         init: {
            //我的信息
            mine: {
                "username": null //我的昵称
                , "id": getParam('imid') //我的ID
                , "avatar": isAgency?agentDefultImg:playerDefultImg //我的头像
                , "sign": "懒得签名"
            }
        }

        //扩展聊天面板工具栏
        , tool: [{
            alias: 'code'
            , title: '代码'
            , iconUnicode: '&#xe64e;'
        }]

       
        ,title: '<i class="layui-icon layui-layim-close layui-icon-left" layim-event="closeIm"></i>' //应用名，默认：我的IM
    });


    //监听自定义工具栏点击，以添加代码为例
    layim.on('tool(code)', function (insert, send) {
        insert('[pre class=layui-code]123[/pre]'); //将内容插入到编辑器
        send();
    });


    //监听查看更多记录
    // layim.on('chatlog', function (data, ul) {
    //     console.log(data);
    //     layim.panel({
    //         title: '与 ' + data.name + ' 的聊天记录' //标题
    //         , tpl: '<div style="padding: 10px;">这里是模版，{{d.data.test}}</div>' //模版
    //         , data: { //数据
    //             test: 'Hello'
    //         }
    //     });
    // });

/*    //模拟"更多"有新动态
    layim.showNew('More', true);
    layim.showNew('find', true);*/

    // layim.setFriendStatus("100003", "hide");


    exports('justchat', layim);
});
